package src.edu.wayne.cs.csc4110.hw6.implementations;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class VideoFrameImpl extends JFrame {
	private static final long serialVersionUID = 7518210752005123891L;
	
	private static VideoFrameImpl videoFrameImpl;

	private JPanel currentPanel;
	private boolean boolPanelSet = false;
	private static final Color frameColor = new Color(59,89,152);
	
	private VideoFrameImpl(){}

	public static synchronized VideoFrameImpl getVideoFrame() {
		
		if (videoFrameImpl == null)
		{
			videoFrameImpl = new VideoFrameImpl();
			videoFrameImpl.setSize(600,480);
			videoFrameImpl.setBackground(VideoFrameImpl.frameColor);
			videoFrameImpl.setLocationRelativeTo(null); // Center the frame
			videoFrameImpl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			videoFrameImpl.setVisible(false);
		}
		return videoFrameImpl;
	}

	public void setCurrentPanel(JPanel newPanel, String newTitle)
	{
		if (boolPanelSet == true)
		{
			videoFrameImpl.setVisible(false);
			videoFrameImpl.remove(currentPanel);
			boolPanelSet = false;
		}
		boolPanelSet = true;
		currentPanel = newPanel;
		videoFrameImpl.add(newPanel);
		videoFrameImpl.setTitle(newTitle);
		videoFrameImpl.validate();
		videoFrameImpl.setVisible(true);
		videoFrameImpl.setResizable(false);
		videoFrameImpl.repaint();
	}
	
	public static Color getColor()
	{
		return VideoFrameImpl.frameColor;
	}
	
}
